#!/bin/bash
svrAddr='http://61.140.221.43:28085/tools/'
platform=`uname -m`
shellname='install'
if [ $platform='aarch64' ]
then
        shellname='64' 
else
        shellname='32'
fi



mkdir -p /home/linaro/work/edge/bin
sudo chown -R norco /home/linaro
sudo chown -R linaro /home/linaro

wget $svrAddr$shellname/libpq5_10.3-1_arm64.deb
sudo dpkg -i libpq5_10.3-1_arm64.deb

wget $svrAddr$shellname/locales_2.27-3ubuntu1_all.deb
sudo dpkg -i locales_2.27-3ubuntu1_all.deb

wget $svrAddr$shellname/ssl-cert_1.0.39_all.deb
sudo dpkg -i ssl-cert_1.0.39_all.deb

wget $svrAddr$shellname/libjemalloc1_3.6.0-11_arm64.deb
sudo dpkg -i libjemalloc1_3.6.0-11_arm64.deb



wget $svrAddr$shellname/redis-tools_4.0.9-1_arm64.deb
sudo dpkg -i redis-tools_4.0.9-1_arm64.deb


wget $svrAddr$shellname/redis-server_4.0.9-1_arm64.deb
sudo dpkg -i redis-server_4.0.9-1_arm64.deb

wget $svrAddr$shellname/locales_2.28-10_all.deb 
sudo dpkg -i locales_2.28-10_all.deb 


wget $svrAddr$shellname/postgresql-client-common_190_all.deb
sudo dpkg -i postgresql-client-common_190_all.deb

wget $svrAddr$shellname/postgresql-common_190_all.deb
sudo dpkg -i postgresql-common_190_all.deb

 


wget $svrAddr$shellname/postgresql-client-9.6_9.6.17-0+deb9u1_arm64.deb
sudo dpkg -i postgresql-client-9.6_9.6.17-0+deb9u1_arm64.deb

wget $svrAddr$shellname/postgresql-9.6_9.6.17-0+deb9u1_arm64.deb
sudo dpkg -i postgresql-9.6_9.6.17-0+deb9u1_arm64.deb

wget $svrAddr$shellname/cron_3.0pl1-128.1ubuntu1_arm64.deb
sudo dpkg -i cron_3.0pl1-128.1ubuntu1_arm64.deb

echo "* * * * * /home/linaro/work/edge/bin/healthy.sh" > /home/linaro/cronfile
echo "@reboot /home/linaro/work/edge/bin/healthy.sh" >> /home/linaro/cronfile
crontab /home/linaro/cronfile


wget -O install.tar.gz  $svrAddr$shellname/disk.tar.gz
tar -zxvf install.tar.gz -C /home/linaro/work/edge/bin/


wget $svrAddr$shellname/dos2unix_7.3.4-3_arm64.deb
sudo dpkg -i dos2unix_7.3.4-3_arm64.deb



chmod 777 /home/linaro/work/edge/bin/*.sh
chmod 777 /home/linaro/work/edge/bin/e*
dos2unix *.sh
sudo service cron start

rm -f *.deb
rm -f *.deb.*
/home/linaro/work/edge/bin/startcron.sh
echo "iotbasePWD" | passwd postgres --stdin > /dev/null 2>&1
sudo su postgres
psql